# -*- coding: utf-8 -*-
import scrapy
import json
from ..items import BeautyItem


class BeautySpider(scrapy.Spider):
    name = 'beauty'
    allowed_domains = ['image.so.com']
    # start_urls = ['http://image.so.com/']
    # 'https://image.so.com/zjl?ch=beauty&sn=30&listtype=new&temp=1'

    def start_requests(self):
        t = 3
        for i in range(2):
            link = 'https://image.so.com/zjl?ch=beauty&sn={}&listtype=new&temp=1'.format(t*30)
            t += 1

            yield scrapy.Request(
                url=link,
                callback=self.parse
            )

    def parse(self, response):
        json_text = json.loads(response.text)
        lists = json_text['list']
        for item in lists:
            beauty_item = BeautyItem()
            beauty_item["img_url"] = item['qhimg_url']
            yield beauty_item

